function personnelLocationCtrl($scope, $http, paFetchService) {
	'ngInject';

	// 百度地图API功能
	let map = new BMap.Map("allmap");
	let currentPoint = new BMap.Point(119.436956,32.165005);
	map.centerAndZoom(currentPoint, 18);
	map.enableScrollWheelZoom();

	let top_left_control = new BMap.ScaleControl({
		anchor: BMAP_ANCHOR_TOP_LEFT
	}); // 左上角，添加比例尺
	let top_left_navigation = new BMap.NavigationControl(); // 左上角，添加默认缩放平移控件
	let top_right_navigation = new BMap.NavigationControl({
		anchor: BMAP_ANCHOR_TOP_RIGHT,
		type: BMAP_NAVIGATION_CONTROL_SMALL
	});   
	map.addControl(top_right_navigation);

	this.staticsInfo = [];
	this.showStaticInfoDialog = true;
	this.queryData = {};

    let _this = $scope;

	// 多边形
	this.addMutilShape = (rectDatas, type) => {
		if(rectDatas == null){
          return;
		}
		let arry = [];
		rectDatas.forEach((point) => {
			arry.push(new BMap.Point(point.lng, point.lat));
		});
		let polygon = new BMap.Polygon(arry, {
			strokeColor: (type == 1 ? "green" : "red"),
			strokeWeight: 4,
			strokeOpacity: 1,
			fillOpacity: 1,
			fillColor: ""
		});
		map.addOverlay(polygon);
	}

	// 圆形
	this.addCircleShape = (cirleData, type) => {
		let point = new BMap.Point(cirleData.lng, cirleData.lat);
		let circle = new BMap.Circle(point, cirleData.radius, {
			strokeColor: (type == 1 ? "green" : "red"),
			strokeWeight: 3,
			strokeOpacity: 0.5,
			fillOpacity: 1,
			fillColor: ""
		});
		map.addOverlay(circle);
	}

	// 标段切换
	this.tabBidItem = () => {
		console.log("bidId === " + this.queryData.bidId);

		//清除所有覆盖物
		map.clearOverlays();

		this.getStaticsInfo();
		this.getPersonList();
		this.getElectricFence();
	}

	// 获取电子围栏
	this.getElectricFence = () => {
		var tenderId = this.queryData.bidId;
		$http
			.post(`${SERVER_CONTEXT}/api/electronFence/findAllFenceByCondition`,{
				tenderId:this.queryData.bidId
			})
			.success((resp) => {
				if (resp.success) {
					resp.data.forEach((item) => {
						if (item.shape == 1) {
							this.addCircleShape(item.cirleData, item.type);
						} else {
							this.addMutilShape(item.rectDatas, item.type);
						}
					});
				}
			})
	}


	// 获取统计信息
	this.getStaticsInfo = () => {
		this.personSum = 0;
		let bidId = this.queryData.bidId;
		$http
			.get(`${SERVER_CONTEXT}/api/construction/getGISStatisticsInfo/` + bidId)
			.success((resp) => {
				if (resp.success) {
					this.staticsInfo = resp.data;
					this.staticsInfo.forEach((item) => {
						this.personSum += item ? parseInt(item.personNum) : 0;
					});
				}
			})
	}

	// 获取施工人员信息
	this.getPersonList = () => {
		var bidId = this.queryData.bidId;
		$http
			.get(`${SERVER_CONTEXT}/api/safesite/workerInfo/getGISPersonInfo/` + bidId)
			.success((resp) => {
				if (resp.success) {
					this.mapAddMarker(resp.data);
				}
			})
	}

	// 向地图添加人员图标及信息
	this.mapAddMarker = (personList) => {
		if (personList && personList.length > 0) {
			let points = [];
			var imageUrl = require(`../../../assets/images/person_location_yellow.png`);
			personList.forEach((person) => {
				let point = new BMap.Point(person.lng,person.lat);
				points.push(point);
				if (person.status == 3) {
					imageUrl = require(`../../../assets/images/person_location_red.gif`);
				}
				if (person.status == 2) {
					imageUrl = require(`../../../assets/images/person_location_green.gif`);
				}
				let marker = new BMap.Marker(point, {
					icon: new BMap.Icon(imageUrl, new BMap.Size(20, 20))
				});
				map.addOverlay(marker);
				let opts = {
					width: 200, // 信息窗口宽度
					height: 100, // 信息窗口高度
					title: "<h3>人员信息</h3>", // 信息窗口标题
				}
				let content = "<p>姓名：" + person.name + "</p>";
				content += "<p>岗位：" + person.quarters + "</p>";
				content += "<p>施工队：" + person.teamName + "</p>";

				let infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象 
				marker.addEventListener("click", function() {
					map.openInfoWindow(infoWindow, point); //开启信息窗口
				});
			});
			map.setViewport(points);
		} else {
			map.centerAndZoom(currentPoint,15);
		}
	}
}

export default personnelLocationCtrl;